package commons.client;

import java.util.ArrayList;
import java.util.List;

import com.amazonaws.services.autoscaling.model.AutoScalingGroup;
import com.amazonaws.services.autoscaling.model.EnabledMetric;
import com.amazonaws.services.autoscaling.model.LaunchConfiguration;

/**
 * Verifies if this class is really necessary, but first we should wait for the next steps.
 * @author Lilia Rodrigues Sampaio - liliars@lsd.com.br
 * 
 */
public class GroupConnection {

	private AutoScalingGroup group;
	private List<EnabledMetric> metrics;
	private List<String> zones;
	
	public GroupConnection(AutoScalingGroup group, List<EnabledMetric> metrics, String configName, String instanceType) {
		this.group = group;
		this.metrics = metrics;
		
		putAvailableZones();
		connect();
		launchConfiguration(configName, instanceType);
	}
	
	private void connect() {
		group.setEnabledMetrics(metrics);
		group.setAvailabilityZones(zones);
	}
	
	private void launchConfiguration(String name, String instanceType) {
		LaunchConfiguration config = new LaunchConfiguration();
		config.setLaunchConfigurationName(name);
		config.setInstanceType(instanceType);
		config.getInstanceMonitoring().setEnabled(true);

		group.setLaunchConfigurationName(config.getLaunchConfigurationName());
	}
	
	private void putAvailableZones() {
		zones = new ArrayList<String>();
		//find out what are the available zones
		zones.add("us-east-1");
		zones.add("us-east-2");
		zones.add("us-west-1");
	}
}
